package com.walterweimod.auxiliary_attributes.mixin;

import com.walterweimod.auxiliary_attributes.event.hooks.ModForgeHooks;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

import static com.walterweimod.auxiliary_attributes.Auxiliary_attributes.getLogger;

@Mixin(Player.class)
public abstract class LivingAbsorptionChangeMixin {
    @Shadow public abstract void remove(Entity.RemovalReason p_150097_);

    @Shadow public abstract void playNotifySound(SoundEvent p_36140_, SoundSource p_36141_, float p_36142_, float p_36143_);

    static {
        System.out.println("LivingAbsorptionChangeMixin loaded!");
    }

    @ModifyVariable(
            method = "setAbsorptionAmount(F)V",
            at = @At("HEAD"),
            argsOnly = true
    )
    private float setAbsorptionAmount(float p_21328_){
        if (((Object) this) instanceof Player player){
            getLogger().info("触发LivingAbsorptionChangeEvent!!!");

            return ModForgeHooks.onLivingAbsorptionChange(player, p_21328_);
        }

        return p_21328_;
    }
}
